﻿Public Class labItem

    'Dim connect As CONDB = CONDB.NewConnection()

    Private code = Nothing
    Private lab_order_code = Nothing
    Private name = Nothing
    Private unit = Nothing
    Private normal = Nothing
    Private comment = Nothing
    Private f_cancel = Nothing
    Private selectLabitem = "SELECT `code` AS 'รหัส lab item', `lab_order_code` AS 'รหัส lab order', `name` AS 'ชื่อ lab item', `unit` AS 'หน่วย', `normal` AS 'normal', `comment` AS 'หมายเหตุ', `f_cancel` AS 'f cancel' FROM lab_item"

    Property code_() As Integer
        Get
            Return code
        End Get
        Set(value As Integer)
            code = value
        End Set
    End Property

    Property lab_order_code_() As Integer
        Get
            Return lab_order_code
        End Get
        Set(value As Integer)
            lab_order_code = value
        End Set
    End Property

    Property name_() As String
        Get
            Return name
        End Get
        Set(value As String)
            name = value
        End Set
    End Property

    Property unit_() As String
        Get
            Return unit
        End Get
        Set(value As String)
            unit = value
        End Set
    End Property

    Property normal_() As String
        Get
            Return normal
        End Get
        Set(value As String)
            normal = value
        End Set
    End Property

    Property comment_() As String
        Get
            Return comment
        End Get
        Set(value As String)
            comment = value
        End Set
    End Property

    Property f_cancel_() As Boolean
        Get
            Return f_cancel
        End Get
        Set(value As Boolean)
            If value = True Then
                f_cancel = 1
            Else
                f_cancel = 0
            End If
        End Set
    End Property

    Property selectLabitem_() As String
        Get
            Return selectLabitem
        End Get
        Set(value As String)
            selectLabitem = value
        End Set
    End Property

    Public Function lookupLabitem(queryLabitem As String)
        Dim lookupLabitemCode As String
        lookupLabitemCode = "SELECT `code` AS 'รหัส lab item', `lab_order_code` AS 'รหัส lab order', `name` AS 'ชื่อ lab item', `unit` AS 'หน่วย', `normal` AS 'normal', `comment` AS 'หมายเหตุ', `f_cancel` AS 'f cancel' FROM lab_item WHERE lab_order_code = '" & queryLabitem & "'"
        Return lookupLabitemCode
    End Function

    Public Sub insertLabItemData()
        Try
            connect = CONDB.NewConnection()
            'connectlocal = conlocal.NewConnection()
            'Dim dischargeID As Integer
            Dim labItemID As Integer
            labItemID = connect.GetTable("SELECT MAX(code) + 1 FROM lab_item").Rows(0)(0)

            connect.ExecuteNonQuery("INSERT INTO lab_item (code, lab_order_code, name, unit, normal, comment, f_cancel) VALUES ('" & labItemID & "', '" & lab_order_code & "', '" & name & "', '" & unit & "', '" & normal & "', '" & comment & "', '" & f_cancel & "')")
            'dischargeID = connect.ExecuteScalar("INSERT INTO masdischarge (DISCHARGE, STATUS) VALUES ('" & masdischargeDescription & "', '" & masdischargeStatus & "'); SELECT LAST_INSERT_ID();")
            'connectlocal.ExecuteNonQuery("INSERT INTO MASDISCHARGE (DISCHGID, DISCHARGE, STATUS) VALUES ('" & dischargeID & "', '" & masdischargeDescription & "', '" & masdischargeStatus & "')")
            MsgBox("ท่านได้ทำการเพิ่มข้อมูลรายการตรวจสอบ Lab เรียบร้อยแล้ว")
        Catch ex As Exception
            MsgBox(vbCrLf & ex.Message)
        End Try
        connect.Dispose()
        'connectlocal.Dispose()
    End Sub

    Public Sub editLabItemData()
        Try
            connect = CONDB.NewConnection()
            'connectlocal = conlocal.NewConnection()

            connect.ExecuteNonQuery("UPDATE lab_item SET lab_order_code = '" & lab_order_code & "', name = '" & name & "', unit = '" & unit & "', normal = '" & normal & "', comment = '" & comment & "', f_cancel = '" & f_cancel & "' WHERE code = '" & code & "'")
            'connectlocal.ExecuteNonQuery("UPDATE MASDISCHARGE SET DISCHARGE = '" & masdischargeDescription & "', STATUS = '" & masdischargeStatus & "' WHERE DISCHGID = '" & masdischargeID & "'")
            MsgBox("ท่านได้ทำการแก้ไขข้อมูลประเภทยาเรียบร้อยแล้ว")
        Catch ex As Exception
            MsgBox(vbCrLf & ex.Message)
        End Try
        connect.Dispose()
        'connectlocal.Dispose()
    End Sub
End Class